<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>文件上传</title>
    <script src="https://cdn.jsdelivr.net/npm/axios@1.7.9/dist/axios.min.js"></script>
  </head>
  <body>
    <h1>文件上传</h1>
    <input type="file" id="file" name="file" required />
    <button onclick="handleSubmit()">上传文件</button>
  </body>
  <script>
    const http = axios.create({
      baseURL: "http://localhost:3000",
      headers: {
        "Content-type": "multipart/form-data",
      },
    });

    function handleSubmit() {
      const file = document.querySelector("#file").files[0];
      const data = new FormData();
      data.append("file", file);
      console.log("你是什么data：", data);
      http.post("/upload", data).then((res) => {
        if (res.status === 400) {
          console.log("没有选择文件");
        } else if (res.status === 200) {
          document.querySelector("#file").innerText = "";
        }
      });
    }
  </script>
</html>
